﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using APPLICATION.Dict;

namespace APPLICATION.Dict.Clients
{
    public partial class Contracts : Form
    {
        public Contracts()
        {
            InitializeComponent();
        }
        private void Clients_Load(object sender, EventArgs e)
        {
            dataSet1.FillClients();
            gridControl1.DataSource = dataSet1.Clients;
            toolStripButtonEdit.Enabled = Convert.ToBoolean(gridView1.SelectedRowsCount);
            toolStripButtonDelete.Enabled = Convert.ToBoolean(gridView1.SelectedRowsCount);
        }

        private void toolStripButtonAdd_Click(object sender, EventArgs e)
        {
            AddClients FrmAddClients = new AddClients();
            FrmAddClients.ShowDialog(this);
        }

        private void toolStripButtonEdit_Click(object sender, EventArgs e)
        {
            if (gridView1.SelectedRowsCount > 0)
            {
                AddClients FrmAddClients = new AddClients(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ClientsID").ToString());
                FrmAddClients.ShowDialog(this);
            }
        }

        private void toolStripButtonDelete_Click(object sender, EventArgs e)
        {
            if (gridView1.SelectedRowsCount > 0)
            {
                if (MessageBox.Show(this, "Would you like delete?", "Client", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    dataSet1.DeleteDataClient(Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ClientsID").ToString()));
                }
            }
        }

        private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
        {
            toolStripButtonEdit.Enabled = Convert.ToBoolean(gridView1.SelectedRowsCount);
            toolStripButtonDelete.Enabled = Convert.ToBoolean(gridView1.SelectedRowsCount);
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            if (gridView1.SelectedRowsCount > 0)
            {
                AddClients FrmAddClients = new AddClients(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ClientsID").ToString());
                FrmAddClients.ShowDialog(this);
            }
        }


    }
}
